package http;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;

/**
 * Created by yangxianming on 2015-06-11.
 */
public class RequestPost implements RequestMethodImpl {
    HttpURLConnection conn = null;
    String urlFull = null;
    Header header = null;

    RequestPost(HttpURLConnection conn, String urlFull, Header header){
        this.conn = conn;
        this.urlFull = urlFull;
        this.header = header;
    }

    public HttpURLConnection sendData (String waitSendData) throws Exception{
//        waitSendData = "username=admin&password=11111111";
//        conn.setChunkedStreamingMode(5);
        conn.setInstanceFollowRedirects(false);
//        conn.connect();
        PrintWriter outData = new PrintWriter(conn.getOutputStream());
//        OutputStream outData = conn.getOutputStream();
        outData.write(waitSendData);

//            发送请求
        outData.flush();
        outData.close();
        return conn;
    }

    @Override
    public HttpURLConnection sendData (Object waitSendData) throws Exception{
        OutputStream outDate = (OutputStream)waitSendData;
//        发送请求
        outDate.flush();
        outDate.close();
        return conn;
    }
}
